import Vue from "vue";
import VueRouter from "vue-router";
import env from '@/assets/js/env'
import buried from "@/utils/buried";
Vue.use(VueRouter);

const routes = [{
    path: "/",
    redirect: "/contract",
    meta: {
        title: "合同项目系统"
    }
},
{
    path: "/analysis", //成果统计分析页
    name: "analysis",
    component: () =>
        import("@views/analysis.vue")
},
{
    path: "/addPage", // 新建中转页
    name: "addPage",
    component: () =>
        import("@views/addPage.vue")
},
{
    path: "/contract", //合同首页
    name: "contract",
    component: () =>
        import("@views/contract/home.vue")
},
{
    path: "/contractstatistics", //合同新建
    name: "contractstatistics",
    component: () =>
        import("@views/contract/contractstatistics.vue"),
	meta:{
		contract:'contract'
	}	
},
{
    path: "/contractdetails", //合同详情
    name: "contractdetails",
    component: () =>
        import("@views/contract/contractdetails.vue")
},
{
    path: "/trackAdd", // 合同追踪新建
    name: "trackAdd",
    component: () =>
        import("@views/contract/track.vue")
},
{
    path: "/trackEdit", // 合同追踪编辑
    name: "trackEdit",
    component: () =>
        import("@views/contract/track.vue")
},
{
    path: "/review", // 普通审核
    name: "review",
    component: () =>
        import("@views/contract/review.vue")
},
{
    path: "/reviewTrack", // 审核追踪
    name: "reviewTrack",
    component: () =>
        import("@views/contract/reviewTrack.vue")
},
{
    path: "/achievements", //成果首页
    name: "achievements",
    component: () =>
        import("@views/achievements/home.vue")
},
{
    path: "/achAdd", // 新建成果
    name: "achAdd",
    component: () =>
        import("@views/achievements/edit.vue"),
	meta:{
		achievements:'achievements'
	}	
},
{
    path: "/details", // 新建成果
    name: "details",
    component: () =>
        import("@views/achievements/details.vue")
},
{
    path: "/achEdit", // 编辑成果
    name: "achEdit",
    component: () =>
        import("@views/achievements/edit.vue")
},
{
    path: "/achTrackAdd", // 成果追踪新建
    name: "achTrackAdd",
    component: () =>
        import("@views/achievements/track.vue")
},
{
    path: "/achTrackEdit", // 成果追踪编辑
    name: "achTrackEdit",
    component: () =>
        import("@views/achievements/track.vue")
},
{
    path: "/achPreviewTrackReivew", // 查看追踪审核
    name: "achPreviewTrackReivew",
    component: () =>
        import("@views/achievements/previewTrackReview.vue")
},
{
    path: "/achReviewTrack", // 审核追踪
    name: "achReviewTrack",
    component: () =>
        import("@views/achievements/reviewTrack.vue")
},
{
    path: "/achReview", // 普通审核
    name: "achReview",
    component: () =>
        import("@views/achievements/review.vue")
},
{
    path: "/achPreviewReview", // 查看普通审核
    name: "achPreviewReview",
    component: () =>
        import("@views/achievements/previewReview.vue")
},
{
    path: "/errPage", // 未找到页面
    name: "errPage",
    component: () =>
        import("@views/errPage.vue"),
    meta: {
        err: true
    }
},
{
    path: "*",
    redirect: "/errPage"
}
];

const router = new VueRouter({
    mode: "history",
    base: process.env.BASE_URL,
    routes
});
/**
 * 重写路由的push方法
 * 主要是为了解决同一个路由路径重复点击报错
 */
const routerPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push (location) {
    return routerPush.call(this, location).catch(error => error);
};

// 路由前置守卫，错误路由信息跳转404

router.beforeEach((to, from, next) => {
    // console.log(to)
	if(to.meta.contract){
		buried("result_add_new", "add_new_contract_fill", { type:to.query.type })
		// console.log(typeof(to.query))
	}
	if(to.meta.achievements){
		buried("result_add_new", "add_new_achieve_fill", { type:to.query.type })
	}
    if (to.meta.err) {
        window.location.href = env.error
		
    }
    next()
})


export default router;
